using System.Collections.Generic;
using System.Text;
using System;
using NHibernate;
using NHibernate.Cfg;
using JVLMRP;
namespace JVLMRP 
{
    public class MRPMasterExportService
    {
        ISession session;

        public MRPMasterExportService(ISession session)
        {
            this.session = session;
        }
        public MRPMasterExportService()
        {
            this.session =SessionFactory.GetNewSession();
        }
        public void InsertMrpmasterexport(MRPMasterExport mrpmasterexportX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Save(mrpmasterexportX);
            tx.Commit();
        }

        public void UpdateMrpmasterexport(MRPMasterExport mrpmasterexportX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Update(mrpmasterexportX);
            tx.Commit();
        }

        public void DeleteMrpmasterexport(MRPMasterExport mrpmasterexportX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Delete(mrpmasterexportX);
            tx.Commit();
        }

        public IList<MRPMasterExport> GetAllMrpmasterexport(Boolean evict)
        {
            IQuery query = session.CreateQuery("select from MRPMasterExport");
            IList<MRPMasterExport> list = query.List<MRPMasterExport>();
            if (evict)
            {
                foreach (MRPMasterExport s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

        public MRPMasterExport GetAllMrpmasterexportByID(String id, Boolean evict)
        {
            IQuery query = session.CreateQuery("select c from MRPMasterExport as c where c.Masterexportcode= :x");
            query.SetString("x", id);
            MRPMasterExport s = (MRPMasterExport)query.UniqueResult();
            if (evict)
            {
                session.Evict(s);
            }
            return s;
        }

        public IList<MRPMasterExport> GetMrpmasterexportByQuery(IQuery query, Boolean evict)
        {
            IList<MRPMasterExport> list = query.List<MRPMasterExport>();
            if (evict)
            {
                foreach (MRPMasterExport s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }
    }
}
